﻿using System;
using System.Globalization;
using System.Linq;
using AddinExpress.OL;
using OL = Microsoft.Office.Interop.Outlook;

namespace uTILLIty.Outlook.FlexFileAddIn
{
	//[System.Runtime.InteropServices.Guid("8FE9C993-040C-4218-9CD3-72F7116DAFA5")]
	//[System.Runtime.InteropServices.ProgId("uTILLIty.OutlookAddIn.FlexFile")]
	public partial class FlexFile
	{

		/*
		 * Extending the User Interface in Outlook 2010:
		 * http://msdn.microsoft.com/en-us/library/office/ee692172.aspx
		 * */

		public static MapiFolderManager MapiFolderManager;

		public ADXOlFormsManager FormsManager;
		public ADXOlFormsCollectionItem PaneIntegrationItem;

		//protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
		//{
		//	_addin = new FlexFileAddin();
		//	_mapiFolderManager = new MapiFolderManager();
		//	_addin.MapiFolderManager = _mapiFolderManager;
		//	return _addin;
		//}

		private void OnStartup(object sender, EventArgs e)
		{
#if DEBUG
      System.Diagnostics.Debug.WriteLine("OnStartup");
#endif
      //System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
			MapiFolderManager = new MapiFolderManager();
			Application.MAPILogonComplete += OnLogonCompleted;

			FormsManager = ADXOlFormsManager.CurrentInstance;
			FormsManager.OnInitialize += FormsManagerOnInitialize;
			FormsManager.Initialize(this);
		}

		private void OnLogonCompleted()
		{
#if DEBUG
      System.Diagnostics.Debug.WriteLine("OnLogonCompleted");
#endif
      MapiFolderManager.BeginLoadingFolders(Application);
		}

		private void OnShutdown(object sender, EventArgs e)
		{
			FormsManager.Finalize(this);
		}

		#region VSTO generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InternalStartup()
		{
			Startup += OnStartup;
			Shutdown += OnShutdown;
		}

		#endregion
	}
}
